#include <stdio.h>

void main(){
	int y,d,m=1,d1;
	scanf("%d %d",&y , &d);
	while (d>0){
		d1=d;
		switch (m){
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
			case 1:d-=31;break;
			case 2:d-=(y%400==0 || y%4==0 && y%100!=0)?29:28;break;
			case 4:
			case 6:
			case 11:
			case 9:d-=30;break;	
		}
		m++;
	}
	printf("%d %d",m-1,d1);
}
